package cn.tedu.start.controller.customer;


import cn.tedu.commons.response.JsonResult;

import cn.tedu.pojo.customer.dto.CustomerLoginAddNewDTO;
import cn.tedu.pojo.customer.dto.CustomerLoginDTO;
import cn.tedu.pojo.customer.entity.CustomerLogin;
import cn.tedu.service.customer.ICustomerLoginService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/customer/log")
@RestController
public class CustomerLoginController {
    @Autowired
    private ICustomerLoginService customerLoginService;

    @ApiOperation("根据id查询用户详情")
    @PostMapping("/selectById")
    @ApiImplicitParam(name = "id",required = true,paramType = "path",dataType = "Long")
    public JsonResult<CustomerLogin> getById(Long id){

        return JsonResult.ok(customerLoginService.getById(id));
    }



    @ApiOperation("增加用户")
    @PostMapping("/add-new")
    public  JsonResult<Void> addNew(CustomerLoginAddNewDTO customerLoginAddNewDTO){
        customerLoginService.addNew(customerLoginAddNewDTO);
        return JsonResult.ok();
    }





    @ApiOperation("根据userName查询用户详情")
    @PostMapping("/selectByName")
    @ApiImplicitParam(name = "userName",required = true,paramType = "path",dataType = "String")
    public JsonResult<CustomerLogin>  getByUserName(String userName){
        return JsonResult.ok(customerLoginService.getByUserName(userName));

    }

    @ApiOperation("根据userName查询密码")
    @PostMapping("/selectPassWordByName")
    @ApiImplicitParam(name = "userName",required = true,paramType = "path",dataType = "String")
    public JsonResult<CustomerLogin> selectPassWord(String userName){
        CustomerLogin passwordByUserName = customerLoginService.getPasswordByUserName(userName);
        return JsonResult.ok(passwordByUserName);
    }


    @ApiOperation("用户登录")
    @PostMapping("/login")
    public  JsonResult<CustomerLoginDTO> login(CustomerLoginDTO customerLoginDTO){
        return JsonResult.ok(customerLoginDTO);
    }

    @ApiOperation("根据用户名查询用户id")
    @PostMapping ("/selectId")
    public JsonResult<CustomerLogin> getIdByUserName(String userName){
        return JsonResult.ok(customerLoginService.getIdByUserName(userName));
    }

    @ApiOperation("根据用户id查询用户名")
    @PostMapping("/selectUserName")
    public JsonResult<CustomerLogin> getUserNameById(Long id){
        return JsonResult.ok(customerLoginService.getUserNameById(id));
    }
    @ApiOperation("根据delete更改用户启用状态")
    @PostMapping("/update/delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "userName",required = true,paramType = "path",dataType = "String"),
            @ApiImplicitParam(name = "isDelete",required = true,paramType = "path",dataType = "Integer")})
    public JsonResult<CustomerLogin> updateDelete(String userName,Integer isDelete){
        return JsonResult.ok(customerLoginService.updateDelete(userName,isDelete));
    }






}
